import time
import datetime
import calendar
import random
from python_baway.common.xcommon import sep

random.seed(2)

sep('Time range')
xst90dt = datetime.datetime(1990, 1, 1, 0, 0, 0, tzinfo=datetime.timezone(datetime.timedelta(hours=0)))
xtstamp90 = xst90dt.timestamp()
xtstamp_now = time.time()

sep('Generate')
person_number2birth_ts_map = {}
for i in range(5):
    person_number2birth_ts_map[i + 1] = random.uniform(xtstamp90, xtstamp_now)

seasons2number_map = {
    (3, 5): [],
    (6, 8): [],
    (9, 10): [],
    (12, 2): []
}
seasons_name_map = {
    (3, 5): '春',
    (6, 8): '夏',
    (9, 10): '秋',
    (12, 2): '冬'
}


def xrotate(m):
    if m >= 3:
        return m
    else:
        return m + 12


sep('Check them')
for xnumber, xtstamp in person_number2birth_ts_map.items():
    dt = datetime.datetime.fromtimestamp(xtstamp)
    d = dt.date()
    print(f"No.{xnumber} person's birth day is {d.isoformat()}")
    xm = d.month
    xmr = xrotate(xm)
    for start, end in seasons2number_map:
        startr = xrotate(start)
        endr = xrotate(end)
        if startr <= xmr <= endr:
            seasons2number_map[(start, end)].append(xnumber)

sep('Statistics')
for start, end in seasons2number_map:
    k = (start, end)
    print(f'Birth in {seasons_name_map[k]}（month {start}~{end}）: ' + ', '.join([str(i) for i in seasons2number_map[k]]))
